package com.course.chapter4;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

public class CAS1 {
    private volatile static  int i =0;
    private volatile static AtomicInteger at =new AtomicInteger();
    private static void increase(){
        i++;
    }
    private static void increase1(){
        at.incrementAndGet();
    }
    public static void main(String[] args) throws IOException, InterruptedException {
        Thread[] threads =new Thread[20];
        for (int i1 = 0; i1 < 10; i1++) {
            threads[i1]=new Thread(()->{
                increase();
            });
            threads[i1].start();
        }

        for (int i1 = 0; i1 < 10; i1++) {
            threads[i1+10] = new Thread(()->{
                increase1();
            });
            threads[i1+10].start();
        }
        for (Thread thread : threads) {
            thread.join();
        }
        System.out.println(i);
        System.out.println(at);
    }
}
